// compile: g++ -o shared_ptr shared_ptr.cc -std=c++11
// run: ./shared_ptr
#include <iostream>

template <typename T>
class MemoryBlock {
 public:
  MemoryBlock() : ptr_(new T[block_size_]) {}
  MemoryBlock(const MemoryBlock& mem) : ptr_(new T[block_size_]) {
    std::cout << "copy memoryblock" << std::endl;
    memcpy(ptr_, mem.GetPtr(), block_size_);
  }
  ~MemoryBlock() {
    std::cout << "deconstruct" << std::endl;
    if (ptr_ != nullptr) {
      delete[] ptr_;
    }
  }

  const T* GetPtr() const { return ptr_; }

 private:
  T* ptr_;
  static const int block_size_ = 1024;
};
void Test1() {
  //   MemoryBlock<int> mem1;
  //   MemoryBlock<int> mem2 = mem1;
  std::shared_ptr<MemoryBlock<int>> sp1 = std::make_shared<MemoryBlock<int>>();
  std::shared_ptr<int> sp2(new int[5]);
}
void Test2() {}
int main() {
  Test1();
  Test2();
  return 0;
}
